@echo off
set MSBUILD="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
set SLN=WebDavSyncTool.sln
set NUGET=".\nuget.exe"

if not exist %MSBUILD% (
    echo MSBuild not found at expected location
    exit /b 1
)

set BUILD_DIR=bin

echo 清理编译目录...
if exist %BUILD_DIR% rd /s /q %BUILD_DIR%
mkdir %BUILD_DIR%

echo 还原NuGet包...
if not exist %NUGET% (
    echo 下载NuGet...
    powershell -Command "Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile nuget.exe"
)
%NUGET% restore %SLN%

echo 使用Fody进行程序集打包...
%MSBUILD% %SLN% /p:Configuration=Release /p:Platform="Any CPU" /p:CosturaCreateTemporaryAssemblies=false

if errorlevel 1 (
    echo Build failed
    exit /b 1
)

echo Build completed successfully